﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentTagVMs
{
    public partial class EquipmentTagListVM : BasePagedListVM<EquipmentTag_View, EquipmentTagSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentTag_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentTag_View>>{
                
                this.MakeGridHeader(x => x.EquipmentTag_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_EquipCode).SetTitle(@Localizer["Page.设备编码"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_DriverType).SetTitle(@Localizer["Page.驱动类型"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_TagName).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_Address).SetTitle(@Localizer["_Admin.Address"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_Description).SetTitle(@Localizer["Page.描述"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_TagType).SetTitle(@Localizer["Page.变量类型"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_DataType).SetTitle(@Localizer["Page.数据类型"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_ScanRate).SetTitle(@Localizer["Page.扫描速率"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_GroupType).SetTitle(@Localizer["Page.信号组"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_AccessMode).SetTitle(@Localizer["Page.访问模式"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_UpLimit).SetTitle(@Localizer["Page.上限"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_LowerLimit).SetTitle(@Localizer["Page.下限"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_ActiveLimit).SetTitle(@Localizer["Page.激活上下限"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentTag_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentTag_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentTag>()
                
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.EquipCode, x=>x.EquipCode)
                .CheckEqual(Searcher.DriverType, x=>x.DriverType)
                .CheckContain(Searcher.TagName, x=>x.TagName)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.TagType, x=>x.TagType)
                .CheckEqual(Searcher.DataType, x=>x.DataType)
                .CheckEqual(Searcher.ScanRate, x=>x.ScanRate)
                .CheckEqual(Searcher.GroupType, x=>x.GroupType)
                .CheckEqual(Searcher.AccessMode, x=>x.AccessMode)
                .CheckEqual(Searcher.UpLimit, x=>x.UpLimit)
                .CheckEqual(Searcher.LowerLimit, x=>x.LowerLimit)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckEqual(Searcher.ActiveLimit, x=>x.ActiveLimit)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentTag_View
                {
				    ID = x.ID,
                    
                    EquipmentTag_Equipment = x.Equipment.EquipName,
                    EquipmentTag_EquipCode = x.Equipment.EquipCode,
                    EquipmentTag_DriverType = x.Equipment.DriverType,
                    EquipmentTag_TagName = x.TagName,
                    EquipmentTag_Address = x.Address,
                    EquipmentTag_Description = x.Description,
                    EquipmentTag_TagType = x.TagType,
                    EquipmentTag_DataType = x.DataType,
                    EquipmentTag_ScanRate = x.ScanRate,
                    EquipmentTag_GroupType = x.GroupType,
                    EquipmentTag_AccessMode = x.AccessMode,
                    EquipmentTag_UpLimit = x.UpLimit,
                    EquipmentTag_LowerLimit = x.LowerLimit,
                    EquipmentTag_Active = x.Active,
                    EquipmentTag_ActiveLimit = x.ActiveLimit,
                    EquipmentTag_CreateTime = x.CreateTime,
                    EquipmentTag_UpdateTime = x.UpdateTime,
                    EquipmentTag_CreateBy = x.CreateBy,
                    EquipmentTag_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentTag_View: EquipmentTag
    {
        
        public string EquipmentTag_Equipment { get; set; }
        public string EquipmentTag_EquipCode { get; set; }
        public DriverTypeEnum? EquipmentTag_DriverType { get; set; }
        public string EquipmentTag_TagName { get; set; }
        public string EquipmentTag_Address { get; set; }
        public string EquipmentTag_Description { get; set; }
        public TagDefineEnum? EquipmentTag_TagType { get; set; }
        public TagDataTypeEnum? EquipmentTag_DataType { get; set; }
        public int? EquipmentTag_ScanRate { get; set; }
        public TagGroupEnum? EquipmentTag_GroupType { get; set; }
        public TagAccessModeEnum? EquipmentTag_AccessMode { get; set; }
        public decimal? EquipmentTag_UpLimit { get; set; }
        public decimal? EquipmentTag_LowerLimit { get; set; }
        public bool? EquipmentTag_Active { get; set; }
        public bool? EquipmentTag_ActiveLimit { get; set; }
        public DateTime? EquipmentTag_CreateTime { get; set; }
        public DateTime? EquipmentTag_UpdateTime { get; set; }
        public string EquipmentTag_CreateBy { get; set; }
        public string EquipmentTag_UpdateBy { get; set; }

    }

}